package com.spring.framework.spel;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.*;

@SuppressWarnings("all")
@Configuration
@PropertySource(value = "classpath:beans/kv.properties", encoding = "UTF-8")
@ComponentScan("com.spring.framework.spel")
public class AnnotationDemo {

	private String property1;

	@Value("#{T(java.util.concurrent.ThreadLocalRandom).current().nextInt(${property2})}")
	private int property2;

	private AnnotationDemo2 annotationDemo2;

	@Value("#{{1,2,3,'${strings}'}}")
	private String[] strings;
	private List<String> stringList;
	private Set<String> stringSet;
	@Value("#{{${property1}:2,'2 -2':3,${objectObjectMap.key}:${objectObjectMap.value},'xx':'yy'}}")
	private Map<Object, Object> objectObjectMap;
	@Value("#{${properties}}")
	private Properties properties;

	@Value("#{{'1','0','1','1'}}")
	private char[] chars;
	@Value("#{{1,2,3,0,11,2}}")
	private byte[] bytes;
	@Value("#{{1,0,1,1}}")
	private float[] floats;
	@Value("#{{1,0,1,1}}")
	private double[] doubles;
	@Value("#{{'1','0','1','1'}}")
	private boolean[] booleans;


	public AnnotationDemo(@Value("#{annotationDemo2.birthplace+'${property1}'}") String property1, @Value(
			"#{annotationDemo2}") AnnotationDemo2 annotationDemo2) {
		this.property1 = property1;
		this.annotationDemo2 = annotationDemo2;
	}

	@Value("#{{1,2,3,3,'${strings}'}}")
	public void setStringList(List<String> stringList) {
		this.stringList = stringList;
	}

	public void setStringSet(@Value("#{${stringSet}}") Set<String> stringSet) {
		this.stringSet = stringSet;
	}

	@Override
	public String toString() {
		return "AnnotationDemo{" +
				"property1='" + property1 + '\'' +
				", property2=" + property2 +
				", annotationDemo2=" + annotationDemo2 +
				", strings=" + Arrays.toString(strings) +
				", stringList=" + stringList +
				", stringSet=" + stringSet +
				", objectObjectMap=" + objectObjectMap +
				", properties=" + properties +
				", chars=" + Arrays.toString(chars) +
				", bytes=" + Arrays.toString(bytes) +
				", floats=" + Arrays.toString(floats) +
				", doubles=" + Arrays.toString(doubles) +
				", booleans=" + Arrays.toString(booleans) +
				'}';
	}
}


